package com.tian.core.action;

import java.util.ArrayList;
import java.util.List;

import org.apache.commons.lang.StringUtils;

import com.tian.core.bean.PageList;
import com.tian.core.bean.Condition;
import com.tian.core.bean.ConditionType;

public class QueryAction extends BaseAction {
	/**
	 * 
	 */
	private static final long serialVersionUID = 8124398123903537698L;

	protected PageList pageList;
	protected int inpages = 1;
	protected int fcpage = 1;
	protected String fcaction = "index";
	protected List<Condition> conditions = new ArrayList<Condition>();
	
	/**
	 * 把conditions条件转化为链接上的参数
	 * @param module 在使用模型驱动时，使用指定模型的名称，否则传null
	 * ****比如Action中用于接收参数的属性是Lable类,名称为label,则此处module值应设置为"label";
	 * ****如果Action中直接使用的各种具体的属性做为传值的参数，则此处module值应设置为null;
	 * @return
	 */
	public String conditions2para(String module){
		StringBuffer result = new StringBuffer();
		if(!conditions.isEmpty()){
			for(Condition condition:conditions){
				if(condition.getType().equals(ConditionType.PROPERTY)){
					if(StringUtils.isEmpty(module)){
						result.append("&").append(condition.getName()).append("=").append(condition.getValue());
					}else{
						result.append("&").append(module).append(".").append(condition.getName()).append("=").append(condition.getValue());
					}
				}
			}
			return result.toString().substring(1);
		}
		return "";
	}
	
	
	//getter & setter
	public PageList getPageList() {
		return pageList;
	}
	public void setPageList(PageList pageList) {
		this.pageList = pageList;
	}
	public int getInpages() {
		return inpages;
	}
	public void setInpages(int inpages) {
		this.inpages = inpages;
	}
	public int getFcpage() {
		return fcpage;
	}
	public void setFcpage(int fcpage) {
		this.fcpage = fcpage;
	}
	public String getFcaction() {
		return fcaction;
	}
	public void setFcaction(String fcaction) {
		this.fcaction = fcaction;
	}
	public List<Condition> getConditions() {
		return conditions;
	}
	public void setConditions(List<Condition> conditions) {
		this.conditions = conditions;
	}
	
}
